package com.ringtheweb.model;

import static javax.persistence.InheritanceType.JOINED;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.CollectionOfElements;


/**
 * A play in a playlist
 * @author ldewavri
 *
 */

@Entity
@Inheritance(strategy = JOINED)
public abstract class Play implements Serializable {
	
	private static final long serialVersionUID = 200L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="PLAY_ID")
	private Long id ;
	
	@Column(name="PLAYED_DATE")
	private Date playedDate;

	@CollectionOfElements
	@JoinColumn(name="PLAY_ID")
	@org.hibernate.annotations.MapKey(columns = @Column(name="PLAY_OPTION_NAME"))
	private Map<String,Serializable> playOptions = new HashMap<String,Serializable>();

	@ManyToOne
	@JoinColumn(name="PLAYLIST_ID",insertable = false,updatable = false)
	private PlayList playlist;


	public Play() {}

	
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}	

	public Date getPlayedDate() {
		return playedDate;
	}

	public void setPlayedDate(Date playedDate) {
		this.playedDate = playedDate;
	}


	public PlayList getPlaylist() {
		return playlist;
	}


	public void addPlayOption(String name,Serializable value) {
		this.playOptions.put(name, value);
	}


	public Map<String,Serializable> getPlayOptions() {
		return playOptions;
	}

	public void setPlayOptions(Map<String,Serializable> playOptions) {
		this.playOptions = playOptions;
	}

}
